package chapter06

object Test17_Extends {

  def main(args: Array[String]): Unit = {
    val student = new Student17("fy",20)

    student.sayHi()
    student.study()

    val person: Person17 = new Student17("alice",22)
    person.sayHi()


    // 类型判断
    println(student.isInstanceOf[Student17]) //true
    println(student.isInstanceOf[Person17])//true
    println(person.isInstanceOf[Student17])//true
    println(person.isInstanceOf[Person17])//true

    // 类型转换
    val student1: Student17 = person.asInstanceOf[Student17]
    student1.study()

    // 相当于Student17.Class
    println(classOf[Student17]) //class chapter06.Student17
    val person2 = new Person17("zhag",45)
    println(person2.isInstanceOf[Student17])//false
  }
}


class Person17(name:String,age:Int) {
  def sayHi(): Unit ={
    println(s"hi from person  +$name")
  }
}
class Student17(name:String,age:Int) extends Person17(name,age){
  override def sayHi(): Unit = {
    println("hi from person " + name)
  }

  def study(): Unit ={
    println("=======study=============")
  }
}
